package com.util.framework;

/**datatable分页请求格式，
 * draw:1
	columns[0][data]:registration_date
	columns[0][name]:
	columns[0][searchable]:true
	columns[0][orderable]:true
	columns[0][search][value]:
	columns[0][search][regex]:false
	columns[1][data]:divident_date
	columns[1][name]:
	columns[1][searchable]:true
	columns[1][orderable]:true
	columns[1][search][value]:
	columns[1][search][regex]:false
	columns[2][data]:xr_date
	columns[2][name]:
	columns[2][searchable]:true
	columns[2][orderable]:true
	columns[2][search][value]:
	columns[2][search][regex]:false
	columns[3][data]:dividend_per_unit
	columns[3][name]:
	columns[3][searchable]:true
	columns[3][orderable]:true
	columns[3][search][value]:
	columns[3][search][regex]:false
	columns[4][data]:draw_bonus_unit
	columns[4][name]:
	columns[4][searchable]:true
	columns[4][orderable]:true
	columns[4][search][value]:
	columns[4][search][regex]:false
	order[0][column]:0
	order[0][dir]:asc
	start:0
	length:10
	search[value]:
	search[regex]:false
 */
public class BaseSearchCondition {
    private String singlePage = "1";
    private Integer pageSize;
    private Integer curPage;
    private Integer firstRecord;

    private String fillPojo = "0";
    //以下为datatable分页参数，搜索和排序暂时不做，后续需要支持，可取order、search字段
    private Integer draw; //请求次数
    private Integer start;//起始行
    private Integer length;//函数

    public Integer getPageSize() {
        if ("1".equals(singlePage)) {
            pageSize = Integer.MAX_VALUE;
        }else if (pageSize == null || pageSize < 1) {
            pageSize = 20;
        }
        return pageSize;
    }

    public Integer getDraw() {
		return draw;
	}

	public void setDraw(Integer draw) {
		this.draw = draw;
	}

	public Integer getStart() {
		return start;
	}

	public void setStart(Integer start) {
		this.start = start;
	}

	public Integer getLength() {
		return length;
	}

	public void setLength(Integer length) {
		this.length = length;
	}

	public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getCurPage() {
        if ("1".equals(singlePage) || curPage == null || curPage < 1) {
            curPage = 1;
        }
        return curPage;
    }

    public void setCurPage(Integer curPage) {
        this.curPage = curPage;
    }

    public Integer getFirstRecord() {
        if ("1".equals(singlePage)) {
            firstRecord = 0;
        } else {
            firstRecord = (getCurPage() - 1) * getPageSize();
        }
        return firstRecord;
    }

    public void setFirstRecord(Integer firstRecord) {
        this.firstRecord = firstRecord;
    }


    public String getSinglePage() {
        return singlePage;
    }

    public void setSinglePage(String singlePage) {
        this.singlePage = singlePage;
    }

    public void setSinglePage(Boolean bolSinglePage) {
        if (bolSinglePage) {
            this.singlePage = "1";
        } else {
            this.singlePage = "0";
        }
    }


    public String getFillPojo() {
        return fillPojo;
    }

    public void setFillPojo(String fillPojo) {
        this.fillPojo = fillPojo;
    }

    public Boolean getFillPojoBol() {
        return "1".equalsIgnoreCase(fillPojo);
    }

    public void setFillPojoBol(Boolean isFillPojo) {
        if (isFillPojo) {
            this.fillPojo = "1";
        } else {
            this.fillPojo = "0";
        }
    }


}
